Skip to content

Oleho/add exception handlers#625

Open
OleHo370 wants to merge 4 commits intomainfrom
oleho/add-exception-handlers
Open

Oleho/add exception handlers#625
OleHo370 wants to merge 4 commits intomainfrom
oleho/add-exception-handlers

Conversation

@OleHo370
Copy link

Purpose

Closes #371 .
Explain the purpose of the PR here if it doesn't match the linked issue. Be sure to add a comment in the linked issue explaining the changes.

New Changes

Added handlers for the custom and common exceptions, and wrote unit tests

Testing

Explain tests that you ran to verify code functionality.

  • I have unit-tested this PR. Otherwise, explain why it cannot be unit-tested.
  • I have included screenshots of the tests performed below.
Screenshot 2025-11-11 at 3 24 55 AM

Outstanding Changes

If there are non-critical changes (i.e. additional features) that can be made to this feature in the future, indicate them here.

@github-actions
Copy link

Pull reviewers stats

Stats of the last 120 days for UWOrbital:

User Total reviews Time to review Total comments
Adityya-K
🥇
58
▀▀▀▀▀
1d 11h 27m
184
▀▀▀▀
camspec
🥈
29
▀▀▀
1d 12h 33m
172
▀▀▀▀
kepler452b123
🥉
14
6d 7h 42m
▀▀
37
Yarik-Popov
3
14h 47m
36
proprogrammer504
2
7d 1h 31m
▀▀
7
sunray4
1
12d 21m
▀▀▀
9
c4bae
1
13d 1h 35m
▀▀▀
2

⚡️ Pull request stats

Copy link
Contributor

@proprogrammer504 proprogrammer504 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. please correct me if i am wrong, but i am under the assumption that this implementation functions by intercepting backend exceptions during API calls and sends a json back to the client detailing the exception, instead of crashing the backend. but only IF the exception came from a client calling some endpoint?

@proprogrammer504
Copy link
Contributor

looks good to me. please correct me if i am wrong, but i am under the assumption that this implementation functions by intercepting backend exceptions during API calls and sends a json back to the client detailing the exception, instead of crashing the backend. but only IF the exception came from a client calling some endpoint?

continuing this, would there be a way to also handle backend exceptions which are not related to endpoints? i believe that this currently cannot handle backend exceptions which are unrelated to endpoints (ie if there was a general process which runs regardless of endpoint calls).

Copy link
Member

@camspec camspec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work overall, but some aspects need to be looked at

"""
return JSONResponse(
status_code=HTTP_400_BAD_REQUEST,
content={"detail": exc.message},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this key is detail and not message?


def setup_exception_handlers(app: FastAPI) -> None:
"""
@brief Add exception handlers to the FastAPI app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you're following our docstring convention for Python

@attribute exc (BaseOrbitalError) - The exception that was raised
"""
return JSONResponse(
status_code=HTTP_400_BAD_REQUEST,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're returning 400 as a fallback for a lot of exceptions, but this is a client-side error that we're returning, even if it wasn't the client's fault. We should also be more specific.

@attribute app (FastAPI) - The FastAPI app to add the exception handlers to
"""

@app.exception_handler(BaseOrbitalError)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would this base exception handler ever be called? What handler is used in the case of a general exception (fallback)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add exception handlers

3 participants